using Com.ContentRendering.Api.DataEngine.Handler.Self;
using System.Collections.Generic;

namespace Com.ContentRendering.Api.DataEngine
{
    /// <summary/>
    public static class SelfReflection
    {
        /// <summary/>
        public static IEnumerator<object> Translate(
            ReflectionCache reflectionCache, 
            object input)
        {            
            // create the parsers
            NullSelfHandler nullSelf = new NullSelfHandler(reflectionCache, input);
            StringSelfHandler stringSelf = new StringSelfHandler(reflectionCache, input);
            BooleanSelfHandler booleanSelf = new BooleanSelfHandler(reflectionCache, input);
            CachedKeyedCollectionSelfHandler cachedDictionarySelf = new CachedKeyedCollectionSelfHandler(reflectionCache, input);
            KeyedCollectionSelfHandler keyedCollectionSelf = new KeyedCollectionSelfHandler(reflectionCache, input);
            EnumerableSelfHandler enumerableSelf = new EnumerableSelfHandler(reflectionCache, input);
            EnumeratorSelfHandler enumeratorSelf = new EnumeratorSelfHandler(reflectionCache, input);
            DefaultSelfHandler defaultSelf = new DefaultSelfHandler(reflectionCache, input);

            // create the chain
            nullSelf.Successor = stringSelf;
            stringSelf.Successor = booleanSelf;
            booleanSelf.Successor = cachedDictionarySelf;
            cachedDictionarySelf.Successor = keyedCollectionSelf;
            keyedCollectionSelf.Successor = enumerableSelf;
            enumerableSelf.Successor = enumeratorSelf;
            enumeratorSelf.Successor = defaultSelf;
            
            // parse the results
            return nullSelf.Parse();
        }
    }
}
